
var token = getCookieValue('token');
//与服务器进行token验证, 验证不通过则跳转到登入页面
// auth_verify();

const sidebarSelf = document.querySelector("#sidebar");
const contentSelf = document.querySelector("#content");
const sidebarChanger = document.querySelector(".sidebar-changer");

var now_content_idx = 0;
var sidebar_zoom_in_state = false;
function change_sidebar_state() {

    sidebar_zoom_in_state = !sidebar_zoom_in_state;
    sidebarSelf.children = '';
    if (sidebar_zoom_in_state) {
        sidebarSelf.style.width = '220px';
        contentSelf.style['margin-left'] = '212px';
        sidebarChanger.style['margin-left'] = '230px';
        sidebarSelf.innerHTML = `
            <li class="news-board">
                <p>公告栏</p>
            </li>
            <li class="user-manage">
                <p>用户管理</p>
            </li>
            <li class="trade-manage">
                <p>交易管理</p>
            </li>
            <li class="section-check">
                <p>机构审查</p>
            </li>
            <li class="police-check">
                <p>公安审查</p>
            </li>
            <li class="deep-check">
                <p>立项调查</p>
            </li>
            <li class="exit-login" onclick="exit_login()">
                <p>退出登入</p>
            </li>
            `;

    } else {
        sidebarSelf.innerHTML = `
            <li class="news-board">
                <p></p>
            </li>
            <li class="user-manage">
                <p></p>
            </li>
            <li class="trade-manage">
                <p></p>
            </li>
            <li class="section-check">
                <p></p>
            </li>
            <li class="police-check">
                <p></p>
            </li>
            <li class="deep-check">
                <p></p>
            </li>
            <li class="exit-login" onclick="exit_login()">
                <p></p>
            </li>
            `;
        sidebarSelf.style.width = '100px';
        contentSelf.style['margin-left'] = '92px';
        sidebarChanger.style['margin-left'] = '110px';
    }

    const sidebar = sidebarSelf.children;
    const content = document.querySelector("#content").children;

    for (var i = 0; i < sidebar.length - 1; i++) {
        sidebar[i].setAttribute('index', i);
        content[i].style.display = 'none';
        sidebar[i].onclick = function () {
            var index = this.getAttribute('index');
            now_content_idx = index;
            for (var j = 0; j < sidebar.length; j++) {
                sidebar[j].classList.remove('selected-state');
            }
            sidebar[index].classList.add('selected-state');

            for (var i = 0; i < content.length; i++) {
                content[i].style.display = 'none';
            }
            content[index].style.display = 'block';

            switch (index) {
                case '0':
                    board_init();
                    break;
                case '1': break;
                case '2':
                    trade_manage_init();
                    break;
                case '3':
                    sector_check_init();
                    break;
                case '4':
                    police_check_init();
                    break;
                case '5': break;
                case '6': break;
            }
        }
    }
    for (var i = 0; i < sidebar.length; i++) {
        if (sidebar_zoom_in_state) {
            sidebar[i].style['padding-left'] = '20%';
        } else {
            sidebar[i].style['padding-left'] = '37%';
        }
    }
    content[now_content_idx].style.display = 'block';
    sidebar[now_content_idx].classList.add('selected-state');
}

change_sidebar_state();

add_float_tip(document.querySelector(".news-board-content .news-board-second #prev-page"), "查看上一篇");
add_float_tip(document.querySelector(".news-board-content .news-board-second #next-page"), "查看下一篇");
add_float_tip(document.querySelector(".news-board-content .news-board-first #prev-page"), "上一页");
add_float_tip(document.querySelector(".news-board-content .news-board-first #next-page"), "下一页");
add_float_tip(document.querySelector(".news-board-content .news-board-first #add-news"), "发布新公告");
add_float_tip(document.querySelector(".news-board-content .news-board-second #return-button"), "返回列表");
